package com.vitabuybuy.tv.ui.tencent.liveroom.ui

import android.os.Bundle
import androidx.appcompat.app.AlertDialog
import androidx.core.os.bundleOf
import com.library.common.base.BaseActivity
import com.library.common.base.MessageModel
import com.library.common.toast.XToast
import com.vitabuybuy.tv.R
import com.vitabuybuy.tv.databinding.ActivityReportLiveAnchorBinding

class ReportLiveAnchorActivity :
    BaseActivity<LiveRoomViewModel, ActivityReportLiveAnchorBinding>() {
    override val isUseBaseTitleBar: Boolean
        get() = true
    override val layoutId: Int
        get() = R.layout.activity_report_live_anchor
    private var liveId: Int? = null
    override fun onGetBundle(bundle: Bundle?) {
        liveId = bundle?.getInt("liveId")
    }

    override fun initView(savedInstanceState: Bundle?) {
        setTitle(getString(R.string.live_report))
    }

    override fun eventHandling() {

        mBinding.btnFinish.setOnClickListener {
            AlertDialog.Builder(this)
                .setTitle(getString(R.string.remind))
                .setMessage(getString(R.string.are_you_sure_report_this_anchor))
                .setCancelable(true)
                .setPositiveButton(getString(R.string.confirm)) { _, _ ->
                    var reortString = ""
                    when (mBinding.rgChoosePay.checkedRadioButtonId) {
                        R.id.rb_report_1 -> {
                            reortString = mBinding.rbReport1.text.toString()
                        }
                        R.id.rb_report_2 -> {
                            reortString = mBinding.rbReport2.text.toString()
                        }
                        R.id.rb_report_3 -> {
                            reortString = mBinding.rbReport3.text.toString()
                        }
                        R.id.rb_report_4 -> {
                            reortString = mBinding.rbReport4.text.toString()
                        }
                    }
                    viewModel.reportAnchor(liveId, reortString)
                }
                .setNegativeButton(getString(R.string.cancel)) { _, _ -> }.create().show()
        }
    }

    override fun handleEvent(msg: MessageModel) {
        when (msg.code) {
            100 -> {
                XToast.success(getString(R.string.thanks_you_are_report))
                finish()
            }
        }
    }


    companion object {
        fun openActivity(mContext: BaseActivity<*, *>, liveId: Int?) {
            mContext.startActivity(
                bundleOf(Pair("liveId", liveId)),
                ReportLiveAnchorActivity::class.java
            )
        }
    }
}
